<?php
	$str = $_POST['txtName'];
	$found_left		= array();
	$found_right 	= array();
	$answer			= array();
	$j = 0;
	for($i = 0; $i < strlen($str); $i++) {
		$prematch	= $str[$i-1].$str[$i];
    if($prematch == '<@') {
    	$found_left[$j] = $i-1; 			
	 	}
		else if($prematch == '@>') {			
 			$found_right[$j] 	= $i;
			$length 					= ($found_right[$j] - 2) - ($found_left[$j] + 1);
			$answer[$j] 			= trim( substr($str, ($found_left[$j]+2), $length) );
			$j++;
	 	}
	}
	print_r($answer);
	
	
	$newStr = $str;
	$k = 0;
	for($i = 0; $i < strlen($str); $i++) {
		$prematch	= $str[$i-1].$str[$i];
    if($prematch == '<@') {
    	$found_left[$k] = $i-1; 			
	 	}
		else if($prematch == '@>') {			
			$obj							= '<input type="text" name="xyz['.$k.']" style="border-style: none; border-bottom-style: groove;" autocomplete="off"/>';
			$found_right[$k] 	= $i;
			$length 					= ($found_right[$k]) - ($found_left[$k]);
			$search 					= substr($str, ($found_left[$k]), ($length+1));
			$newStr 					= str_replace($search, $obj, $newStr);
			$k++;
	 	}
	}
	echo '<br>'.$newStr;
	
	$cnt = $_POST['hidval'];
	for($i = 0; $i < $cnt; $i++){
	echo '<br>'.$_POST['xyz'.$i];
	}

?>
<meta charset="utf-8" />
